package com.wu.system.controller.wx;

import cn.hutool.core.util.StrUtil;
import com.wu.common.entity.SecurityUser;
import com.wu.common.page.PageResult;
import com.wu.common.utils.Result;
import com.wu.dao.sys.vo.SysUserVO;
import com.wu.dao.weixin.vo.WeixinMenuVO;
import com.wu.entity.sys.SysUserEntity;
import com.wu.entity.weixin.po.WeixinMenu;
import com.wu.service.sys.convert.SysUserConvert;
import com.wu.service.sys.query.SysUserQuery;
import com.wu.service.weixin.service.WxMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 战队管理
 *
 * @author wzd 
 */
@RestController
@RequestMapping("wx/menu")
@AllArgsConstructor
@Tag(name="微信菜单管理")
public class WxMenuController {
    @Autowired
    private WxMenuService wxMenuService;


    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('sys:user:page')")
    public Result<PageResult<WeixinMenuVO>> page(@Valid SysUserQuery query){
        PageResult<WeixinMenuVO> page = wxMenuService.page(query);
        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('sys:user:info')")
    public Result<WeixinMenuVO> get(@PathVariable("id") String id){
        WeixinMenuVO entity = wxMenuService.selectById(id);
        return Result.ok(entity);
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('sys:user:delete')")
    public Result<String> delete(@RequestBody List<String> idList){
        wxMenuService.deleteByIds(idList);
        return Result.ok();
    }


    @PostMapping
    @Operation(summary = "保存")
    @PreAuthorize("hasAuthority('sys:user:save')")
    public Result<String> save(@RequestBody @Valid WeixinMenuVO vo){
        // 保存
        wxMenuService.save(vo);
        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    @PreAuthorize("hasAuthority('sys:user:update')")
    public Result<String> update(@RequestBody @Valid WeixinMenuVO vo){
        wxMenuService.update(vo);
        return Result.ok();
    }

   /* @PostMapping("/{id}")
    @Operation(summary = "同步微信菜单")
    @PreAuthorize("hasAuthority('sys:user:save')")
    public Result<String> save(@PathVariable("id") String id){
        // 保存
        wxMenuService.save(vo);
        return Result.ok();
    }*/

}
